package javango.conf;

import java.util.ArrayList;
import java.util.List;

import javango.core.Url;
import javango.core.Urls;
import javango.core.contextprocessors.ContextProcessor;
import javango.middleware.Middleware;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author johns
 *
 */
public class SimpleSettings extends BaseSettings {

	protected List<Class<? extends Middleware>> middlewareClasses = new ArrayList<Class<? extends Middleware>>();
	protected Class<? extends Urls> urlsClass;
	protected List<Class<? extends ContextProcessor>> contextProcessorClasses = new ArrayList<Class<? extends ContextProcessor>>();
	
	private final static Log log = LogFactory.getLog(Settings.class);

	public List<ContextProcessor> getContextProcessorList() {
		if (contextProcessorList.isEmpty()) {
			for (Class<? extends ContextProcessor> clazz : contextProcessorClasses) {
				contextProcessorList.add(injector.getInstance(clazz));
			}
		}
		return contextProcessorList;
	}

	public List<Middleware> getMiddlewareList() {
		if (middlewareList.isEmpty()) {
			for (Class<? extends Middleware> clazz : middlewareClasses) {
				middlewareList.add(injector.getInstance(clazz));
			}

		}
		return middlewareList;
	}

	public List<Url> getUrlList() {
		if (urlList.isEmpty()) {			
			Urls urls = (Urls)injector.getInstance(urlsClass);
			urlList.addAll(urls.getUrlPatterns());
		}
		return urlList;
	}

	public List<Class<? extends Middleware>> getMiddlewareClasses() {
		return middlewareClasses;
	}

	public void setMiddlewareClasses(
			List<Class<? extends Middleware>> middlewareClasses) {
		this.middlewareClasses = middlewareClasses;
	}

	public Class<? extends Urls> getUrlsClass() {
		return urlsClass;
	}

	public void setUrlsClass(Class<? extends Urls> urlsClass) {
		this.urlsClass = urlsClass;
	}

	public List<Class<? extends ContextProcessor>> getContextProcessorClasses() {
		return contextProcessorClasses;
	}

	public void setContextProcessorClasses(
			List<Class<? extends ContextProcessor>> contextProcessorClasses) {
		this.contextProcessorClasses = contextProcessorClasses;
	}

}
